const express = require('express');
const router = express.Router();
const multer = require('multer');
const path = require('path');
const fileController = require('../controllers/fileController');

// 配置文件上传
const storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, path.join(__dirname, '../../uploads/'));
  },
  filename: function (req, file, cb) {
    const ext = path.extname(file.originalname);
    cb(null, `${Date.now()}-${Math.round(Math.random() * 1E9)}${ext}`);
  }
});

const upload = multer({
  storage: storage,
  limits: {
    fileSize: 100 * 1024 * 1024, // 100MB
  }
});

// 文件上传路由
router.post('/upload', upload.single('file'), fileController.uploadFile);

// 文件转换路由
router.post('/convert', fileController.convertFile);

// 获取转换进度
router.get('/progress/:id', fileController.getProgress);

// 下载转换后的文件
router.get('/download/:filename', fileController.downloadFile);

module.exports = router; 